package com.atguigu.activemq_learn.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service;

import javax.jms.TextMessage;

/**
 * 整合spring，主题消息生产者
 */
@Service
public class SpringMQ_Topic_Produce {
    @Autowired
    private JmsTemplate jmsTemplate;

    public static void main(String[] args) {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        SpringMQ_Topic_Produce produce = (SpringMQ_Topic_Produce) applicationContext.getBean("springMQ_Topic_Produce");
        produce.jmsTemplate.send((session) -> {
            TextMessage textMessage = session.createTextMessage("我是spring发送的topic消息");
            return textMessage;
        });
        System.out.println("生产者发送消息完成");
    }

}
